﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using TimKen.DataAccess;
 
namespace TimKen.BussLogic
{
    /// <summary>
    /// 类IndustryProduct。
    /// </summary>
    public class IndustryProduct
    {
        public IndustryProduct()
        { }
        #region Model
        private int _industryid;
        private int _productid;
        /// <summary>
        /// 
        /// </summary>
        public int IndustryID
        {
            set { _industryid = value; }
            get { return _industryid; }
        }
        /// <summary>
        /// 
        /// </summary>
        public int ProductID
        {
            set { _productid = value; }
            get { return _productid; }
        }
        #endregion Model


        #region  成员方法


        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int IndustryID, int ProductID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from IndustryProduct");
            strSql.Append(" where IndustryID=@IndustryID and ProductID=@ProductID ");

            SqlParameter[] parameters = {
					new SqlParameter("@IndustryID", SqlDbType.Int,4),
					new SqlParameter("@ProductID", SqlDbType.Int,4)};
            parameters[0].Value = IndustryID;
            parameters[1].Value = ProductID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }




        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public IndustryProduct(int IndustryID, int ProductID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select IndustryID,ProductID ");
            strSql.Append(" FROM IndustryProduct ");
            strSql.Append(" where IndustryID=@IndustryID and ProductID=@ProductID ");
            SqlParameter[] parameters = {
					new SqlParameter("@IndustryID", SqlDbType.Int,4),
					new SqlParameter("@ProductID", SqlDbType.Int,4)};
            parameters[0].Value = IndustryID;
            parameters[1].Value = ProductID;

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["IndustryID"].ToString() != "")
                {
                    IndustryID = int.Parse(ds.Tables[0].Rows[0]["IndustryID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ProductID"].ToString() != "")
                {
                    ProductID = int.Parse(ds.Tables[0].Rows[0]["ProductID"].ToString());
                }
            }
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into IndustryProduct(");
            strSql.Append("IndustryID,ProductID)");
            strSql.Append(" values (");
            strSql.Append("@IndustryID,@ProductID)");
            SqlParameter[] parameters = {
					new SqlParameter("@IndustryID", SqlDbType.Int,4),
					new SqlParameter("@ProductID", SqlDbType.Int,4)};
            parameters[0].Value = IndustryID;
            parameters[1].Value = ProductID;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int IndustryID, int ProductID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from IndustryProduct ");
            strSql.Append(" where IndustryID=@IndustryID and ProductID=@ProductID ");
            SqlParameter[] parameters = {
					new SqlParameter("@IndustryID", SqlDbType.Int,4),
					new SqlParameter("@ProductID", SqlDbType.Int,4)};
            parameters[0].Value = IndustryID;
            parameters[1].Value = ProductID;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }

        #endregion  成员方法
    }
}

